package com.softserveinc.autorent.manager;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import com.softserveinc.autorent.model.CarModel;



@Stateless
public class CarModelEJB extends AbstractEJB<CarModel> {
	
	@PersistenceContext(unitName = "jpa")
	private EntityManager em;

	@Override
	public EntityManager getEntityManager() {
		return em;
	}

	@Override
	public void setEntityManager(EntityManager em) {
		this.em = em;
	}
	
	public CarModelEJB() {
		super(CarModel.class);
	}
/*@NamedQueries({
@NamedQuery(name = "CarModel.findAll", query = "SELECT m FROM CarModel m"),
@NamedQuery(name = "CarModel.findById", query = "SELECT m FROM CarModel m WHERE m.id = :id"),
@NamedQuery(name = "CarModel.findAllByCarVendorId", query = "SELECT m FROM CarModel m WHERE m.carVendor.id = :id")
})*/
	@Override
    public List<CarModel> findAll() {
        TypedQuery<CarModel> query = em.createNamedQuery("CarModel.findAll", CarModel.class);
        return query.getResultList();
    }
    public List<CarModel> findById(int id) {
        TypedQuery<CarModel> query = em.createNamedQuery("CarModel.findById", CarModel.class);
        query.setParameter("id", id);
        return query.getResultList();
    }

    public List<CarModel> findAllByCarVendorId(int id) {
        TypedQuery<CarModel> query = em.createNamedQuery("CarModel.findAllByCarVendorId", CarModel.class);
        query.setParameter("id", id);        
        return query.getResultList();
    }
    

}
